package com.oa.resources.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.oa.common.config.OAConfig;
import com.oa.common.core.domain.entity.SysDictData;
import com.oa.common.utils.DateUtils;
import com.oa.common.utils.SecurityUtils;
import com.oa.common.utils.file.FileUtils;
import com.oa.resources.mapper.OaResourcesMapper;
import com.oa.system.service.ISysDictTypeService;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.oa.resources.domain.OaResources;
import com.oa.resources.service.IOaResourcesService;

/**
 * 资源管理Service业务层处理
 * 
 * @author li.ziye
 * @date 2022-05-18
 */
@Service
public class OaResourcesServiceImpl implements IOaResourcesService 
{
    @Autowired
    private OaResourcesMapper oaResourcesMapper;

    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 查询资源管理
     * 
     * @param resourcesId 资源管理主键
     * @return 资源管理
     */
    @Override
    public OaResources selectOaResourcesByResourcesId(Long resourcesId)
    {
        return oaResourcesMapper.selectOaResourcesByResourcesId(resourcesId);
    }

    /**
     * 查询资源管理列表
     * 
     * @param oaResources 资源管理
     * @return 资源管理
     */
    @Override
    public List<OaResources> selectOaResourcesList(OaResources oaResources)
    {
        return oaResourcesMapper.selectOaResourcesList(oaResources);
    }

    /**
     * 新增资源管理
     * 
     * @param oaResources 资源管理
     * @return 结果
     */
    @Override
    public int insertOaResources(OaResources oaResources)
    {
        oaResources.setCreateBy(SecurityUtils.getUsername());
        oaResources.setCreateTime(DateUtils.getNowDate());
        return oaResourcesMapper.insertOaResources(oaResources);
    }


    /**
     * 修改资源管理
     * 
     * @param oaResources 资源管理
     * @return 结果
     */
    @Override
    public int updateOaResources(OaResources oaResources)
    {
        oaResources.setUpdateTime(DateUtils.getNowDate());
        return oaResourcesMapper.updateOaResources(oaResources);
    }

    /**
     * 批量删除资源管理
     * 
     * @param resourcesIds 需要删除的资源管理主键
     * @return 结果
     */
    @Override
    public int deleteOaResourcesByResourcesIds(Long[] resourcesIds)
    {
        OaResources oaResources = new OaResources();
        for (Long resourcesId : resourcesIds){
            oaResources = oaResourcesMapper.selectOaResourcesByResourcesId(resourcesId);
            String filePath = oaResources.getResourcesPath();
            filePath = OAConfig.getUploadPath() + filePath.substring(filePath.indexOf("upload")+6, filePath.length());
            FileUtils.deleteFile(filePath);
        }
        return oaResourcesMapper.deleteOaResourcesByResourcesIds(resourcesIds);
    }

    /**
     * 删除资源管理信息
     * 
     * @param resourcesId 资源管理主键
     * @return 结果
     */
    @Override
    public int deleteOaResourcesByResourcesId(Long resourcesId)
    {
        return oaResourcesMapper.deleteOaResourcesByResourcesId(resourcesId);
    }
}
